import pymssql
import pymysql


def mysql_function(sql, sql_type):
    try:
        mysql_conn = pymysql.connect(host='127.0.0.1', user='root', password='123456', database='scanentry', charset='UTF8')
        # mysql_conn = pymysql.connect(host='172.16.6.88', user='dormitorytest', password='tNzi6neC26RSMBFb',database='dormitorytest', charset='UTF8')
        mysql_cursor = mysql_conn.cursor()
        mysql_emp_sql = sql
        mysql_cursor.execute(mysql_emp_sql)
        if sql_type == 'select':
            mssql_data_list = mysql_cursor.fetchall()
            mysql_cursor.close()
            mysql_conn.close()
            return mssql_data_list
        elif sql_type == 'insert':
            mysql_conn.commit()
            mysql_cursor.close()
            mysql_conn.close()
            return 'success'
    except Exception as e:
        print(e)
        return e
